x = 'aaabcdabcd'
result = ''
count = 1

for i in range(len(x) - 1):
    if x[i + 1] == x[i]:
        count += 1
    else:
        if count > 1:
            result = result + str(count) + x[i]
        else:
            result = result + x[i]
        count = 1
print(result)
